import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, Query, UseGuards } from '@nestjs/common';
import { NoticeService } from './notice.service';
import { AuthGuard } from '@nestjs/passport';
import { ApiResponse, ApiOperation, ApiBody, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { IdDto } from 'src/common/dto/dto';
import { GetNoticeDto, CreateNoticeDto, UpdateNoticeDto } from './dto/notice.dto';
import { NoticeResult } from './entities/notice.entity';
@ApiBearerAuth() // swagger文档设置token
@ApiTags('公告')
@Controller('admin/notice')
export class NoticeController {
  constructor(private readonly noticeService: NoticeService) { }
  /** 公告 */
  @HttpCode(200)
  @Get('/getNoticePage')
  @ApiResponse({
    status: 200,
    description: '公告列表',
    type: NoticeResult,
  })
  @ApiOperation({
    tags: ['获取公告'],
    summary: '获取公告',
    operationId: 'getNoticePage',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  getNoticePage(@Query() params: GetNoticeDto) {
    return this.noticeService.getNoticePage(params);
  }
  @HttpCode(200)
  @Post('/createNotice')
  @ApiBody({
    description: '创建公告',
    type: CreateNoticeDto,
  })
  @ApiOperation({
    summary: '创建公告',
    operationId: 'createNotice',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async createNotice(@Body() body: CreateNoticeDto) {
    return this.noticeService.createNotice(body);
  }
  @HttpCode(200)
  @Post('/updateNotice')
  @ApiBody({
    description: '更新公告信息',
    type: UpdateNoticeDto,
  })
  @ApiOperation({
    summary: '更新公告信息',
    operationId: 'updateNotice',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async updateNotice(@Body() body: UpdateNoticeDto) {
    return this.noticeService.updateNotice(body);
  }
  @HttpCode(200)
  @Post('/deleteNotice')
  @ApiBody({
    description: '删除公告',
    type: IdDto,
  })
  @ApiOperation({
    summary: '删除公告',
    operationId: 'deleteNotice',
  })
  @UseGuards(AuthGuard('jwt')) // 自定义守卫
  async deleteNotice(@Body() body: IdDto) {
    return this.noticeService.deleteNotice(body);
  }
}
